<?php

require_once(sfConfig::get('sf_lib_dir').'/filter/base/BaseFormFilterPropel.class.php');

/**
 * Skola filter form base class.
 *
 * @package    dnevnik
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterGeneratedTemplate.php 16976 2009-04-04 12:47:44Z fabien $
 */
class BaseSkolaFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'tip'                 => new sfWidgetFormFilterInput(),
      'skola_id'            => new sfWidgetFormPropelChoice(array('model' => 'Skola', 'add_empty' => true)),
      'ime'                 => new sfWidgetFormFilterInput(),
      'okrug_id'            => new sfWidgetFormPropelChoice(array('model' => 'Okrug', 'add_empty' => true)),
      'mesto'               => new sfWidgetFormFilterInput(),
      'adresa'              => new sfWidgetFormFilterInput(),
      'opstina'             => new sfWidgetFormFilterInput(),
      'telefon'             => new sfWidgetFormFilterInput(),
      'fax'                 => new sfWidgetFormFilterInput(),
      'web'                 => new sfWidgetFormFilterInput(),
      'maticni_broj'        => new sfWidgetFormFilterInput(),
      'sifra_skole'         => new sfWidgetFormFilterInput(),
      'klasa'               => new sfWidgetFormFilterInput(),
      'resenje_br'          => new sfWidgetFormFilterInput(),
      'resenje_dat'         => new sfWidgetFormFilterInput(),
      'delovodni_br'        => new sfWidgetFormFilterInput(),
      'resenje_organ'       => new sfWidgetFormFilterInput(),
      'clanarina'           => new sfWidgetFormFilterInput(),
      'tip_obrasca'         => new sfWidgetFormFilterInput(),
      'created_at'          => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => true)),
      'menadzer_skola_list' => new sfWidgetFormPropelChoice(array('model' => 'Menadzer', 'add_empty' => true)),
      'upravnik_skola_list' => new sfWidgetFormPropelChoice(array('model' => 'Upravnik', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'tip'                 => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'skola_id'            => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Skola', 'column' => 'id')),
      'ime'                 => new sfValidatorPass(array('required' => false)),
      'okrug_id'            => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Okrug', 'column' => 'id')),
      'mesto'               => new sfValidatorPass(array('required' => false)),
      'adresa'              => new sfValidatorPass(array('required' => false)),
      'opstina'             => new sfValidatorPass(array('required' => false)),
      'telefon'             => new sfValidatorPass(array('required' => false)),
      'fax'                 => new sfValidatorPass(array('required' => false)),
      'web'                 => new sfValidatorPass(array('required' => false)),
      'maticni_broj'        => new sfValidatorPass(array('required' => false)),
      'sifra_skole'         => new sfValidatorPass(array('required' => false)),
      'klasa'               => new sfValidatorPass(array('required' => false)),
      'resenje_br'          => new sfValidatorPass(array('required' => false)),
      'resenje_dat'         => new sfValidatorPass(array('required' => false)),
      'delovodni_br'        => new sfValidatorPass(array('required' => false)),
      'resenje_organ'       => new sfValidatorPass(array('required' => false)),
      'clanarina'           => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'tip_obrasca'         => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'created_at'          => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'menadzer_skola_list' => new sfValidatorPropelChoice(array('model' => 'Menadzer', 'required' => false)),
      'upravnik_skola_list' => new sfValidatorPropelChoice(array('model' => 'Upravnik', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('skola_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addMenadzerSkolaListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(MenadzerSkolaPeer::SKOLA_ID, SkolaPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(MenadzerSkolaPeer::MENADZER_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(MenadzerSkolaPeer::MENADZER_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function addUpravnikSkolaListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(UpravnikSkolaPeer::SKOLA_ID, SkolaPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(UpravnikSkolaPeer::UPRAVNIK_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(UpravnikSkolaPeer::UPRAVNIK_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Skola';
  }

  public function getFields()
  {
    return array(
      'id'                  => 'Number',
      'tip'                 => 'Number',
      'skola_id'            => 'ForeignKey',
      'ime'                 => 'Text',
      'okrug_id'            => 'ForeignKey',
      'mesto'               => 'Text',
      'adresa'              => 'Text',
      'opstina'             => 'Text',
      'telefon'             => 'Text',
      'fax'                 => 'Text',
      'web'                 => 'Text',
      'maticni_broj'        => 'Text',
      'sifra_skole'         => 'Text',
      'klasa'               => 'Text',
      'resenje_br'          => 'Text',
      'resenje_dat'         => 'Text',
      'delovodni_br'        => 'Text',
      'resenje_organ'       => 'Text',
      'clanarina'           => 'Number',
      'tip_obrasca'         => 'Number',
      'created_at'          => 'Date',
      'menadzer_skola_list' => 'ManyKey',
      'upravnik_skola_list' => 'ManyKey',
    );
  }
}
